package com.itheima.config;

import com.itheima.pojo.Apple;
import com.itheima.pojo.User;
import org.springframework.boot.autoconfigure.condition.ConditionalOnBean;
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Conditional;
import org.springframework.context.annotation.Configuration;

/**
 * @Author weizhongli
 * @Date 2020/4/22
 * @Version v1.0
 * @Description
 **/
@Configuration
public class UserConfig {

    @Bean
    public Apple apple(){
        return new Apple();

    }

    @Bean
    //@ConditionalOnMissingBean(Apple.class) //代表如果beanFactory没有apple bean 则创建userBean
    //@ConditionalOnBean(Apple.class) //代表如果beanFactory有apple bean 则创建userBean
    //@Conditional(ClassCondition.class)
    @ConditionalOnProperty(name = "itheima",havingValue = "364") //配置文件中有数据 才能创建
    public User user(){
        User user = new User();
        user.setName("lisi");
        user.setAge(22);
        return user;
    }
}
